import Vue from 'vue'
import VueRouter from 'vue-router'
// 引入登录页面
import Login from '@/views/Login.vue'
// 引入首页
import Index from '@/views/Index.vue'
// 引入后台主页
import Background from '@/views/Background.vue'
/**
 * 引入组件
 */
import OrderBar from '@/components/NavBar/orderBar.vue'
import Seats from '@/components/seats/seats.vue'
import CategoryBar from '@/components/NavBar/categoryBar.vue'
import CategoryManage from '@/components/BackManage/categoryManage.vue'
import DishManage from '@/components/BackManage/dishManage.vue'
import TableManage from '@/components/BackManage/tableManage.vue'

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/index', redirect: '/index/category' },
  { path: '/background', redirect: '/background/tableManage' },
  { path: '/login', component: Login },
  {
    path: '/index',
    component: Index,
    children: [
      {
        path: 'orders',
        component: OrderBar
      },
      { path: 'seats', component: Seats },
      {
        path: 'category',
        component: CategoryBar
      }
    ]
  },
  {
    path: '/background',
    component: Background,
    children: [
      { path: 'categoryManage', component: CategoryManage },
      { path: 'dishManage', component: DishManage },
      { path: 'tableManage', component: TableManage }
    ]
  }
]

const router = new VueRouter({
  routes
})
// // 全局前置守卫
// router.beforeEach(function (to, from, next) {
//   if (to.path === '/login') {
//     next()
//   } else {
//     next('/login')
//   }
// })
export default router
